package com.icoopoo.flux.webflux;

import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * @ClassName HellowordController
 * @Description TODO
 * @Author lh
 * @Date 2021/3/1 16:53
 * @Version 1.0
 **/
@Component
public class GreetingHandler {

    public Mono<ServerResponse> hello(ServerRequest request) {

        HttpMethod method = request.method();
        System.out.println(method.name());
        return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN)
                .body(BodyInserters.fromValue(request.attribute("hao")+"  nihao"));
    }

    public Mono<ServerResponse> hello2(ServerRequest request) {

        HttpMethod method = request.method();
        System.out.println(method.name());
        request.attribute("attra");
        return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN)
                .body(BodyInserters.fromValue(request.attribute("hao2")+"  nihao2"));
    }
}
